package com.zhixiang.xaec.action.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.system.TemplateAttributes;
import com.zhixiang.xaec.service.system.TemplateAttributesService;
@Controller
@Scope("prototype")
public class TemplateAttributesAction extends BaseAction
{

    private static final long serialVersionUID = 8506104331194254233L;
    @Autowired
    TemplateAttributesService templateAttributesService;
    
    TemplateAttributes templateAttributes;

    public TemplateAttributes getTemplateAttributes()
    {
        return templateAttributes;
    }

    public void setTemplateAttributes(TemplateAttributes templateAttributes)
    {
        this.templateAttributes = templateAttributes;
    }
    
    public String list(){
        QueryFilter localQueryFilter=new QueryFilter(getRequest());
        List<TemplateAttributes> localList=templateAttributesService.getAll(localQueryFilter);
        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
        setResult(localList);
        return SUCCESS;
    }
    
    public String save(){
        templateAttributesService.save(templateAttributes);
        setResult(templateAttributesService.findAttriBytId(templateAttributes.getTemplate().getId()));
        return SUCCESS;
    }
    
    public String delete(){
        String[] ids=getRequest().getParameterValues("ids");
        String tId=getRequest().getParameter("tId");
        templateAttributesService.delete(ids);
        //返回当前的自定义属性，重新显示在form中
        if(!"".equals(tId)&&tId!=null){
        setResult(templateAttributesService.findAttriBytId(Long.valueOf(tId)));
        }
        return SUCCESS;
    }
}
